package com.example.springbooteasycode.utils.tablepdf.bad;

import org.apache.poi.xwpf.usermodel.*;

import java.io.FileOutputStream;
import java.io.IOException;

public class simpleG {
    public static void main(String[] args) throws IOException{
        XWPFDocument document = new XWPFDocument();

        //创建一个XWPFTable对象
        XWPFTable table = document.createTable();

        //设置表格的样式
        table.setTableAlignment(TableRowAlign.CENTER);

        //创建表头行
//        XWPFTableRow headerRow = table.getRow(0);
        XWPFTableRow headerRow = table.createRow();


        //创建表头单元格
        XWPFTableCell headerCell = headerRow.createCell();
        XWPFTableCell headerCell1 = headerRow.createCell();

        //设置表头单元格的内容和样式
        headerCell.setText("表头");
        headerCell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
        headerCell.setColor("C0C0C0");

        headerCell1.setText("表头");
        headerCell1.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
        headerCell1.setColor("C0C0C0");

        //创建数据行和数据单元格
        XWPFTableRow dataRow = table.createRow();
        XWPFTableCell dataCell = dataRow.createCell();

        //设置数据单元格的内容和样式
        dataCell.setText("数据");
        dataCell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);

        //写入到Word文档
        // 输出到文件
        try (FileOutputStream out = new FileOutputStream("/Users/boykchen/Desktop/poiSimple.docx")) {
            document.write(out);
        }


    }
}
